#ifndef __CONTACT_HANDLER_H__
#define __CONTACT_HANDLER_H__

#include <glib.h>
#include <pthread.h>
#include "./window.h"

// Elemento della lista contact_ts_list
typedef struct{
	gchar * contact_id;	// id del contatto
	glong last_received;	// ultimo messaggio ricevuto
} contact_time_stamp;

// Lista dei time stamp
GList *contact_ts_list;


void new_contact_ts(gchar *contact_id);
void renew_contact_ts(gchar *contact_id);
contact_time_stamp *get_contact_ts(gchar * contact_id);
void delete_contact_ts(gchar * contact_id);
void delete_expired_contact();
void delete_contact_ts_list();
void print_contact_ts_list();

// Handler del thread per lo scheduling della contact_ts_list
pthread_t contact_ts_list_thread;

// Mutex della lista contact_ts_list
pthread_mutex_t contact_ts_list_mutex;

// Macro per la gestione thread e mutex
#define contact_ts_list_lock() 		pthread_mutex_lock(&contact_ts_list_mutex)
#define contact_ts_list_unlock() 	pthread_mutex_unlock(&contact_ts_list_mutex)
#define contact_ts_list_init_lock()	pthread_mutex_init(&contact_ts_list_mutex, NULL)
#define contact_ts_list_destroy_lock()	pthread_mutex_destroy(&contact_ts_list_mutex)
#define thread_check_for_expired_ts()	pthread_create(&contact_ts_list_thread, NULL, delete_expired_contact, NULL);

#endif
